package com.acmedcare.framework.exchange.center.jmx;


import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class RabbitUtils {


  private static Channel channel;

  private static void initRabbitChannel() throws IOException, TimeoutException {

    if (channel == null) {
      ConnectionFactory factory = new ConnectionFactory();
      factory.setHost("rabbit.acmedcare.com");
      factory.setPort(5670);
      factory.setConnectionTimeout(1000);
      factory.setUsername("admin");
      factory.setPassword("admin");

      Connection connection = factory.newConnection();
      channel = connection.createChannel();
    }
  }

  public static Channel getRabbitChannel() throws IOException, TimeoutException {
    if (channel == null) {
      initRabbitChannel();
    }
    return channel;
  }
}
